package com.team1.supervend.domain;

import java.io.BufferedInputStream;
import java.util.Scanner;

public class MaintenanceHandler {
	Boolean maint;
	ProductInventory currentProductInventory;
	MaintenanceHandler(ProductInventory currentProductInventory){
		this.currentProductInventory = currentProductInventory;
		
	}
	
	public Boolean setMaintMode(int is_Maint) {
		maint = false;
		if (is_Maint == 1234){
			System.out.println("Setting maintenance mode");
			maint = true;
			maintenance();
		}
		
		else if (is_Maint == 0){
			System.out.println("Releasing maintenance mode");
			maint = false;
		}
			
		else{
			System.out.println("Incorrect Password -- please try again");
			maint = false;
		}
		return maint;
	}
	
	public Boolean maintenance(){
		System.out.println("The current inventory status  is shown below ");
		System.out.println(" ");
		currentProductInventory.printProductDescriptions();
		System.out.println("To add an item press 1 or press 0 to return to menu ");
		Scanner option = new Scanner(new BufferedInputStream(System.in));
		switch ( option.nextInt() ){
		case 0:
			maint = false;
			setMaintMode(0);
			break;
		case 1:
			addProductInventory();
			currentProductInventory.printProductDescriptions();
			break;
		default:
			System.out.println("try again");
			maintenance();
		}
		return maint;
	}
	
	public Boolean addProductInventory(){
		System.out.println("enter item data with a space delimiting each field" +
				" enter id, cost, description, quantity and min quantity required");
		final Scanner item = new Scanner (new BufferedInputStream(System.in));
		int pid = item.nextInt();
		float pcost = item.nextFloat();
		String pdesc = item.next();
		int pqty = item.nextInt();
		int pminqty = item.nextInt();
		
		ProductInventoryItem pitem = new ProductInventoryItem( new ItemID( pid ), new PaymentAmount( pcost ), pdesc, pqty, pminqty );
		currentProductInventory.StockProductInventory(pitem);
		System.out.println("qty "+ pqty+" "+pdesc+" Added to inventory");
		maintenance();
		return true;
		
	}
	
	public Boolean addProductInventory(int id, float cost, String desc, int qty, int minqty){
		
		ProductInventoryItem item = new ProductInventoryItem( new ItemID( id ), new PaymentAmount( cost ), desc, qty, minqty );
		currentProductInventory.StockProductInventory(item);
		System.out.println("qty "+ qty+" "+desc+" Added to inventory");
		return true;
	}

}
